package com.gsm.projects.jobDw.mock;

import com.github.javafaker.Faker;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class GraduatesDataGenerator {

    public static void main(String[] args) {

        // 数据库配置
        String url = "jdbc:mysql://localhost:3306/db_job_realtime_statistics?useSSL=false&serverTimezone=UTC&useUnicode=true&characterEncoding=UTF-8";
        String user = "root";
        String password = "123456";

        // 毕业年限范围
        int startYear = 2023; // 开始年份
        int endYear = 2024;   // 结束年份

        try (Connection conn = DriverManager.getConnection(url, user, password)) {
            Faker faker = new Faker(new Locale("zh_CN"));
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            String sql = "INSERT INTO Graduates (college_id, name, student_number, gender, major, graduation_year, degree, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
            PreparedStatement stmt = conn.prepareStatement(sql);

            for (int i = 1; i <= 2869; i++) {

                stmt.setInt(1, i); // college_id

                for(int j = 0 ; j < 1000 ; j++)
                {
                    stmt.setString(2, faker.name().fullName()); // name
                    stmt.setString(3, String.format("%04d", j)); // student_number
                    stmt.setString(4, faker.options().option("M", "F")); // gender
                    stmt.setString(5, faker.educator().course()); // major
                    stmt.setInt(6, faker.number().numberBetween(startYear, endYear)); // graduation_year
                    stmt.setString(7, faker.options().option("专科", "本科" , "硕士" , "博士" )); // degree
                    stmt.setString(8, dateFormat.format(new Date())); // created_at
                    stmt.setString(9, dateFormat.format(new Date())); // updated_at

                    stmt.addBatch();
                }

                stmt.executeBatch();

            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

}